﻿using System.Collections.Generic;
using System.IO;

namespace AdvancedScriptEditor
{
    /// <summary>
    /// Stores a list of functions and their descriptions.
    /// </summary>
    public class FunctionList
    {
        public string[] Functions;
        public string[] Descriptions;

        public void Save(string functionsFilename, string descriptionsFilename)
        {
            string[] functions = Functions;
            string[] descriptions = Descriptions;

            for (int i = 0; i < descriptions.Length; i++)
                descriptions[i] = descriptions[i].Replace("\n", "\\n");

            File.WriteAllLines(functionsFilename, functions);
            File.WriteAllLines(descriptionsFilename, descriptions);
        }

        public void Load(string functionsFilename, string descriptionsFilename)
        {
            Functions = File.ReadAllLines(functionsFilename);
            Descriptions = File.ReadAllLines(descriptionsFilename);

            for (int i = 0; i < Descriptions.Length; i++)
                Descriptions[i] = Descriptions[i].Replace("\\n", "\n");
        }
    }

    /// <summary>
    /// Stores various options used by FramelessScriptEditor.
    /// </summary>
    public class Options
    {
        public bool AutomaticallyShowAutocomplete;

        public void Save(string filename)
        {
            string[] text =
            {
                @"[Options]",
                @"AutomaticallyShowAutocomplete=" + AutomaticallyShowAutocomplete.ToString(),
            };
            File.WriteAllLines(filename, text);
        }

        public void Load(string filename)
        {
            string[] text = File.ReadAllLines(filename);
            string[] asa = new string[text.Length];

            foreach (string line in text)
                if (line.StartsWith("AutomaticallyShowAutocomplete"))
                    asa = line.Split('=');

            AutomaticallyShowAutocomplete = bool.Parse(asa[1]);
        }
    }
}
